package org.seeplnframework.skyeye.common.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Utils {

    /**
     * md5加密
     * @param plainText
     * @return
     */
    public static String encryption(String plainText) {
        String re_md5 = new String();
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(plainText.getBytes());
            byte b[] = md.digest();
            int i;
            StringBuffer buf = new StringBuffer("");
            for (int offset = 0; offset < b.length; offset++) {
                i = b[offset];
                if (i < 0)
                    i += 256;
                if (i < 16)
                    buf.append("0");
                buf.append(Integer.toHexString(i));
            }
            re_md5 = buf.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return re_md5;
    }

    public static void main(String[] args) {
        String str = "org.springframework.mail.MailSendException: Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 550 Connection frequency limited at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:459) ~[spring-context-support-4.1.7.RELEASE.jar:4.1.7.RELEASE] at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:345) ~[spring-context-support-4.1.7.RELEASE.jar:4.1.7.RELEASE] at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:340) ~[spring-context-support-4.1.7.RELEASE.jar:4.1.7.RELEASE] at com.mgateway.utils.MailUtil.sendMail(MailUtil.java:106) ~[mgateway-core-1.1.0-SNAPSHOT.jar:na] at com.mgateway.utils.MailUtil.exceptionMail(MailUtil.java:146) ~[mgateway-core-1.1.0-SNAPSHOT.jar:na] at com.mgateway.apps.channel.xwyh.proxy.XWYHLoanProxy.handle(XWYHLoanProxy.java:175) [mgateway-core-1.1.0-SNAPSHOT.jar:na] at com.mgateway.apps.channel.xwyh.proxy.XWYHLoanProxy.handle(XWYHLoanProxy.java:50) [mgateway-core-1.1.0-SNAPSHOT.jar:na] at com.mgateway.ext.service.impl.LoanTaskServiceImpl$1.run(LoanTaskServiceImpl.java:571) [mgateway-core-1.1.0-SNAPSHOT.jar:na] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_92] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_92] at java.lang.Thread.run(Thread.java:745) [na:1.8.0_92]";
        String resultStr = encryption(str);
        System.out.println("MD5加密结果:"+resultStr);
    }

}
